package com.restaurant.serviceimpl;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.restaurant.domain.Vendertype;
import com.restaurant.service.VendertypeService;

public class VendertypeServiceImpl implements VendertypeService {

   private HibernateTemplate hibernateTemplate;

   @Autowired
   public void setSessionFactory(SessionFactory sessionFactory){
       this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Vendertype addOrModify( Vendertype objVendertype ) {
       return ( Vendertype ) hibernateTemplate.merge( objVendertype );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Vendertype deleteRecord( Vendertype objVendertype ) {
       hibernateTemplate.delete( objVendertype );
       return objVendertype;
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Vendertype modifyRecord( Vendertype objVendertype ) {
       return ( Vendertype ) hibernateTemplate.merge( objVendertype );
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Vendertype> loadAll() {
       return (List<Vendertype>)hibernateTemplate.findByNamedQuery( "Vendertype.findAll");
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Vendertype loadByPrimaryKey( Long primaryKey ) {
       return (Vendertype) hibernateTemplate.get( Vendertype.class, primaryKey );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Vendertype deleteByPrimaryKey( Long primaryKey ) {
       return deleteRecord(loadByPrimaryKey(primaryKey));
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Vendertype> loadByHql(String query) {
       return ( List<Vendertype> ) hibernateTemplate.find( query );
   }
}